<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/6
 * Time: 11:26
 */

namespace App\Http\Controllers\Home;


use App\Http\Controllers\Controller;
use App\Model\Members;
use Illuminate\Http\Request;
use Session;
use App\Model\MembersLevel;

class BaseController extends Controller
{
    public $user = null;
    public $uid = null;
    public function __construct()
    {
        $this->request = request();
//         验证是否登录
        $this->middleware(function ($request, $next) {
            $users = $request->session()->get('home_user');
            if(empty($users)){
                return redirect( '/home/login/login' )->withErrors('重新登录！');
            }
//                $userLeve = MembersLevel::where('id',$users['level'])->first();
//                if($users['credit3']>$userLeve['credit3'] && $request->getRequestUri()!='/home/straightShop/index'){
//                   return redirect('/home/straightShop/index');
//
//                }

            return $next($request);
        });
    }

    public function sees(Request $request)
    {
//        $this->middleware(function ($request, $next) {
//            $users =session('home_user');
//            dump($users);
//        });
//        $users =session('home_user');
//        dump($users);
    }

    public function isMeet()
    {
        $this->request = request();
//         验证是否登录
        $this->middleware(function ($request, $next) {
            $users = $request->session()->get('home_user');
            $userLeve = MembersLevel::where('id',$users['level'])->first();
            if($users['credit6']>$userLeve['credit3'] && $request->getRequestUri()!='/home/straightShop/index'){
                return redirect('/home/straightShop/index');

            }

            return $next($request);
        });
    }

}